package com.wuliupai.delivery.wuliupaidelivery.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.wuliupai.delivery.wuliupaidelivery.R;
import com.wuliupai.delivery.wuliupaidelivery.db.CityHistoryBean;

import java.util.List;

/**
 * Created by CME on 16/7/5.
 * Description 选择始发地的历史记录Adapter
 */
public class CityHistoryAdapter extends BaseAdapter {

    private Context context;
    private List<CityHistoryBean> historyList;

    public CityHistoryAdapter(Context context, List<CityHistoryBean> historyList) {
        this.context = context;
        this.historyList = historyList;
    }

    @Override
    public int getCount() {
        return historyList == null ? 0 : historyList.size();
    }

    @Override
    public Object getItem(int position) {
        return (historyList == null) && (historyList.size() == 0) ? null : historyList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_select_place_history_grid, null);
            holder.tv_history = (TextView) convertView.findViewById(R.id.tv_history);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        CityHistoryBean bean = historyList.get(position);

        StringBuilder sb = new StringBuilder();
        String area = bean.getArea();
        String city = bean.getCity();
        String province = bean.getProvince();
        sb.append(province).append(" ").append(city).append(" ").append(area);
//        if (bean.isAllCountry()) {
//            holder.tv_history.setText(context.getString(R.string.strings_select_place_all_country));
//        } else {
//            if (!MyUtil.isNotNull(area)) {
//                sb.append(province);
//                if (MyUtil.isNotNull(city)) {
//                    sb.append(city);
//                }
//            } else {
//                sb.append(city).append(area);
//            }
//            holder.tv_history.setText(sb.toString());
//        }
            holder.tv_history.setText(sb.toString());
        return convertView;
    }

    class ViewHolder {
        TextView tv_history;
    }
}
